package org.edu.model;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import org.hibernate.annotations.Proxy;

@Entity
@Proxy(lazy = false)
@Table(name = "ROLES_SCIENCY", catalog = "SCHOOL")
public class RolesSciency implements Serializable {

	private static final long serialVersionUID = 1L;

	private Long roles_sciency_id;
	private Set<User> users = new HashSet<>();
	private String sciency_name;
	private Boolean panel_sciency;

	@Id
	@GeneratedValue
	@Column(name = "ROLES_SCIENCY_ID")
	public Long getRoles_sciency_id() {
		return roles_sciency_id;
	}

	public void setRoles_sciency_id(Long roles_sciency_id) {
		this.roles_sciency_id = roles_sciency_id;
	}

	@OneToMany(targetEntity = User.class, mappedBy = "rolesSciency", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	@LazyCollection(LazyCollectionOption.FALSE)
	public Set<User> getUsers() {
		return users;
	}

	public void setUsers(Set<User> users) {
		this.users = users;
	}

	@Column(name = "SCIENCY_NAME")
	public String getSciency_name() {
		return sciency_name;
	}

	public void setSciency_name(String sciency_name) {
		this.sciency_name = sciency_name;
	}

	@Column(name = "PANEL_SCIENCY")
	public Boolean getPanel_sciency() {
		return panel_sciency;
	}

	public void setPanel_sciency(Boolean panel_sciency) {
		this.panel_sciency = panel_sciency;
	}

	public RolesSciency() {
		super();
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((panel_sciency == null) ? 0 : panel_sciency.hashCode());
		result = prime
				* result
				+ ((roles_sciency_id == null) ? 0 : roles_sciency_id.hashCode());
		result = prime * result
				+ ((sciency_name == null) ? 0 : sciency_name.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		RolesSciency other = (RolesSciency) obj;
		if (panel_sciency == null) {
			if (other.panel_sciency != null)
				return false;
		} else if (!panel_sciency.equals(other.panel_sciency))
			return false;
		if (roles_sciency_id == null) {
			if (other.roles_sciency_id != null)
				return false;
		} else if (!roles_sciency_id.equals(other.roles_sciency_id))
			return false;
		if (sciency_name == null) {
			if (other.sciency_name != null)
				return false;
		} else if (!sciency_name.equals(other.sciency_name))
			return false;
		return true;
	}

}
